<?php

namespace StudyBuddy;

/**
 * Abstract class represents submitted question
 * Question can be submitted via web form, via email,
 * nntp, API, by parsing external API
 * each one of these should implement own concrete
 * class with concrete methods that would return
 * the same types of values
 */
abstract class SubmittedQuestion extends StudyBuddyObject {

    protected $oLevel;
    protected $oSubject;
    protected $oChapter;
    protected $oDif;
    protected $oUser;

    /**
     * Object represents body of
     * submitted question
     *
     * @var object of type Utf8String
     */
    protected $oBody;

    /**
     *
     * Object representing Title of question
     *
     * @var object of type Utf8String
     */
    protected $oTitle;

    /**
     * Object representing tags string
     *
     *  @var object of type Utf8String
     */
    protected $oTags;

    abstract public function getLevel();

    abstract public function getSubject();

    abstract public function getChapter();
    
    abstract public function getDif();

    /**
     * Array of question tags
     *
     * @var array
     */
    //protected $aTags;

    /**
     * Get object of type User of user
     * who posted the question
     *
     * @return object of type User
     */
    abstract public function getUserObject();

    /**
     * @return object of type Utf8String representing
     * the body of the question
     */
    abstract public function getBody();

    /**
     * @return object of type Utf8string representing
     * the title string of question
     */
    abstract public function getTitle();

    /**
     * @return string ip address from where question
     * was posted
     */
    abstract public function getIP();

    /**
     * Get array of tags, with all
     * elements (all tags) in lower case
     *
     * And also guarantees that array values are
     * unique (no duplicate tags in same array)
     *
     * @return array of tags, guaranteed to be
     * unique and in lower case
     */
    public final function getTagsArray() {
        if (!isset($this->aTags)) {
            $oTags = $this->getUtf8Tags();
            $this->aTags = TagsTokenizer::factory($oTags)->getArrayCopy();
        }

        return $this->aTags;
    }

    /**
     * Get object of type Utf8String
     * representing submitted tags
     *
     * Enter description here ...
     */
    abstract public function getUtf8Tags();

    /**
     * Concrete class may override this to provide
     * array of data that should be added to question data
     * array from which the question object Question
     * is created.
     *
     * @return associative array
     */
    public function getExtraData() {
        return array();
    }

    /**
     * Get name of app used for submitting
     * this question
     * @return string
     */
    public function getApp() {
        return '';
    }

    /**
     * Get id of app used for submitting
     * this question
     * @return null
     */
    public function getAppId() {
        return null;
    }

    /**
     * Get id of link to app used for submitting
     * this question
     *
     * @return null
     */
    public function getAppLink() {
        $name = $this->getApp();
        $id = $this->getAppId();

        return (!empty($id) && !empty($name)) ? \sprintf('<a href="/app/%s" rel="nofollow" target="_blank">%s</a>', $id, $name) : null;
    }

}
